<?php
/**
 * Created by PhpStorm.
 * User: yangzhic
 * Date: 2016/12/31
 * Time: 10:23
 */

namespace SDXApi\Behaviors;


use Think\Behavior;
use Think\Cache\Driver\Redis;

class QueueBehavior extends Behavior {
    private $queue;

    public function run(&$params)
    {
        // TODO: Implement run() method.
        if(!empty($params)){
            $this->queue = new Redis();
            $hook = $params['fun'];
            $data = $params['data'];
            if(!empty($hook)){
                $this->$hook($data);
            }
        }
        return;
    }

    /**
     * 从队列中清除
     * @param $data
     */
    public function queue_remove($data){
        if(empty($this->queue)){
            $this->queue = new Redis();
        }

        $this->queue->lRem($data['key'],$data['code'],0);
        S($data['key'].'_'.$data['code'],null);
    }

    public function queue_add($data){

    }
}